package com.jinyao.exploit.common.base.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.jinyao.exploit.common.base.User;
import com.jinyao.exploit.common.utils.IdGen;
import com.jinyao.exploit.common.utils.StringUtils;
import com.jinyao.exploit.common.utils.UserUtils;
import lombok.Data;

import java.util.Date;

/***********************************************************************
 * 文件说明：用于数据库实体
 * 创建信息：李晋 2018-10-9 15:24
 * 变更履历： 
 ***********************************************************************/
@Data
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class DataEntity<T> extends BaseEntity<T> {

  /**
   * 删除标记（0：正常；1：删除）
   */
  public static final String DELETE_FLAG_NORMAL = "0";
  public static final String DELETE_FLAG_DELETE = "1";

  private Long createBy;  // 创建者
  private Date createDate;  // 创建日期
  private Long updateBy;  // 更新者
  private Date updateDate;  // 更新日期
  private String remarks;   // 备注
  @TableLogic
  private String deleteFlag;   // 删除标记

  public DataEntity() {
    super();
    this.deleteFlag = "0";
  }

  public DataEntity(long id) {
    super(id);
    this.deleteFlag = "0";
  }

  @TableField(exist = false)
  private boolean newRecord = false;

  public boolean isNewRecord(){
    return newRecord || id == null;
  }

  public void preInsert(){
    if(id == null){
      setId(IdGen.sfId());
    }
    createBy = UserUtils.getUserId();
    createDate = new Date();
    updateBy = UserUtils.getUserId();
    updateDate = new Date();
  }

  public void preUpdate(){
    createBy = UserUtils.getUserId();
    createDate = new Date();
    updateBy = UserUtils.getUserId();
    updateDate = new Date();
  }
}
